package org.social.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import static org.social.db.StaticResource.DynamicCommodityResource.*;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.tools.SK_String;
import com.xiaoleilu.hutool.util.StrUtil;
import org.social.db.cache.DynamicCommodityCache;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.social.db.StaticResource.DynamicCommodityResource.*;
/**
 * 动态商品
 */
public class DynamicCommodity extends BasePojo<DynamicCommodity> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[1];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* 商品名称
	*/
	private String name;
	
	/**
	* 所属商店
	*/
	private int storeId;
	
	/**
	* 格子编号
	*/
	private int[] grid;
	
	/**
	* 标签
	*/
	private String tagIcon;
	
	/**
	* 开启条件
	*/
	private int openContType;
	
	/**
	* 开启值
	*/
	private int openContVal;
	
	/**
	* 权重(随机商店生效)
	*/
	private int weight;
	
	/**
	* 限购
	*/
	private int limitType;
	
	/**
	* 限购值
	*/
	private int limitVal;
	
	/**
	* 全服限购额外限制个人购买的数量
	*/
	private int serLimit;
	
	/**
	* 出售时间
	*/
	private String sellTime;
	
	/**
	* 道具
	*/
	private Map goods;
	
	/**
	* 价格类型
	*/
	private int[] priceType;
	
	/**
	* 价格数量
	*/
	private int[] priceVal;
	
	/**
	* 描述
	*/
	private String des;
	
	/**
	* 上架时间
	*/
	private java.util.Date addedTime;
	
	/**
	* 下架时间
	*/
	private java.util.Date shelfTime;
	
	/**
	* 状态
	*/
	private int status;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static DynamicCommodity builder() {
		DynamicCommodity dynamicCommodity = new DynamicCommodity();
		return dynamicCommodity;
	}
	
	@Deprecated
	public DynamicCommodity() {
		super();
	}
	
	public DynamicCommodity(int id, String name, int storeId, int[] grid, String tagIcon, int openContType, int openContVal, int weight, int limitType, int limitVal, int serLimit, String sellTime, Map goods, int[] priceType, int[] priceVal, String des, java.util.Date addedTime, java.util.Date shelfTime, int status) {
		super();
		this.id = id;
		this.name = name;
		this.storeId = storeId;
		this.grid = grid;
		this.tagIcon = tagIcon;
		this.openContType = openContType;
		this.openContVal = openContVal;
		this.weight = weight;
		this.limitType = limitType;
		this.limitVal = limitVal;
		this.serLimit = serLimit;
		this.sellTime = sellTime;
		this.goods = goods;
		this.priceType = priceType;
		this.priceVal = priceVal;
		this.des = des;
		this.addedTime = addedTime;
		this.shelfTime = shelfTime;
		this.status = status;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public DynamicCommodity setId(int id) {this.id = id;return this;}
	
	/**
	 * 商品名称
	 */
	public String getName() {return name;}
	
	/**
	 * 商品名称
	 */
	public DynamicCommodity setName(String name) {this.name = name;return this;}
	
	/**
	 * 所属商店
	 */
	public int getStoreId() {return storeId;}
	
	/**
	 * 所属商店
	 */
	public DynamicCommodity setStoreId(int storeId) {this.storeId = storeId;return this;}
	
	/**
	 * 格子编号
	 */
	public int[] getGrid() {return grid;}
	
	/**
	 * 格子编号
	 */
	public DynamicCommodity setGrid(int[] grid) {this.grid = grid;return this;}
	
	/**
	 * 格子编号
	 */
	public String getGridString() {
	    return toJSONString(grid);
	}
	
	/**
	 * 格子编号
	 */
	public int[] initGridString(String str) {
		return forJsonObject(str,int[].class);
	}	
	/**
	 * 标签
	 */
	public String getTagIcon() {return tagIcon;}
	
	/**
	 * 标签
	 */
	public DynamicCommodity setTagIcon(String tagIcon) {this.tagIcon = tagIcon;return this;}
	
	/**
	 * 开启条件
	 */
	public int getOpenContType() {return openContType;}
	
	/**
	 * 开启条件
	 */
	public DynamicCommodity setOpenContType(int openContType) {this.openContType = openContType;return this;}
	
	/**
	 * 开启值
	 */
	public int getOpenContVal() {return openContVal;}
	
	/**
	 * 开启值
	 */
	public DynamicCommodity setOpenContVal(int openContVal) {this.openContVal = openContVal;return this;}
	
	/**
	 * 权重(随机商店生效)
	 */
	public int getWeight() {return weight;}
	
	/**
	 * 权重(随机商店生效)
	 */
	public DynamicCommodity setWeight(int weight) {this.weight = weight;return this;}
	
	/**
	 * 限购
	 */
	public int getLimitType() {return limitType;}
	
	/**
	 * 限购
	 */
	public DynamicCommodity setLimitType(int limitType) {this.limitType = limitType;return this;}
	
	/**
	 * 限购值
	 */
	public int getLimitVal() {return limitVal;}
	
	/**
	 * 限购值
	 */
	public DynamicCommodity setLimitVal(int limitVal) {this.limitVal = limitVal;return this;}
	
	/**
	 * 全服限购额外限制个人购买的数量
	 */
	public int getSerLimit() {return serLimit;}
	
	/**
	 * 全服限购额外限制个人购买的数量
	 */
	public DynamicCommodity setSerLimit(int serLimit) {this.serLimit = serLimit;return this;}
	
	/**
	 * 出售时间
	 */
	public String getSellTime() {return sellTime;}
	
	/**
	 * 出售时间
	 */
	public DynamicCommodity setSellTime(String sellTime) {this.sellTime = sellTime;return this;}
	
	/**
	 * 道具
	 */
	public Map getGoods() {return goods;}
	
	/**
	 * 道具
	 */
	public DynamicCommodity setGoods(Map goods) {this.goods = goods;return this;}
	
	/**
	 * 道具
	 */
	public String getGoodsString() {
	    return toJSONString(goods);
	}
	
	/**
	 * 道具
	 */
	public Map initGoodsString(String str) {
		return forJsonObject(str,Map.class);
	}	
	/**
	 * 价格类型
	 */
	public int[] getPriceType() {return priceType;}
	
	/**
	 * 价格类型
	 */
	public DynamicCommodity setPriceType(int[] priceType) {this.priceType = priceType;return this;}
	
	/**
	 * 价格类型
	 */
	public String getPriceTypeString() {
	    return toJSONString(priceType);
	}
	
	/**
	 * 价格类型
	 */
	public int[] initPriceTypeString(String str) {
		return forJsonObject(str,int[].class);
	}	
	/**
	 * 价格数量
	 */
	public int[] getPriceVal() {return priceVal;}
	
	/**
	 * 价格数量
	 */
	public DynamicCommodity setPriceVal(int[] priceVal) {this.priceVal = priceVal;return this;}
	
	/**
	 * 价格数量
	 */
	public String getPriceValString() {
	    return toJSONString(priceVal);
	}
	
	/**
	 * 价格数量
	 */
	public int[] initPriceValString(String str) {
		return forJsonObject(str,int[].class);
	}	
	/**
	 * 描述
	 */
	public String getDes() {return des;}
	
	/**
	 * 描述
	 */
	public DynamicCommodity setDes(String des) {this.des = des;return this;}
	
	/**
	 * 上架时间
	 */
	public java.util.Date getAddedTime() {return addedTime;}
	
	/**
	 * 上架时间
	 */
	public DynamicCommodity setAddedTime(java.util.Date addedTime) {this.addedTime = addedTime;return this;}
	
	/**
	 * 下架时间
	 */
	public java.util.Date getShelfTime() {return shelfTime;}
	
	/**
	 * 下架时间
	 */
	public DynamicCommodity setShelfTime(java.util.Date shelfTime) {this.shelfTime = shelfTime;return this;}
	
	/**
	 * 状态
	 */
	public int getStatus() {return status;}
	
	/**
	 * 状态
	 */
	public DynamicCommodity setStatus(int status) {this.status = status;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected DynamicCommodity setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected DynamicCommodity setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.name;
        values[2] = this.storeId;
        values[3] = this.grid;
        values[4] = this.tagIcon;
        values[5] = this.openContType;
        values[6] = this.openContVal;
        values[7] = this.weight;
        values[8] = this.limitType;
        values[9] = this.limitVal;
        values[10] = this.serLimit;
        values[11] = this.sellTime;
        values[12] = this.goods;
        values[13] = this.priceType;
        values[14] = this.priceVal;
        values[15] = this.des;
        values[16] = this.addedTime;
        values[17] = this.shelfTime;
        values[18] = this.status;
        values[19] = this.createDate;
        values[20] = this.modifiedDate;
        return values;
	}
	
	public DynamicCommodity deepCopy(){
		DynamicCommodity dynamicCommodity = null;
		try {
			dynamicCommodity = (DynamicCommodity) super.clone();
		    dynamicCommodity.setGrid(ToolCopy.copyObject(this.grid));
		    dynamicCommodity.setGoods(ToolCopy.copyObject(this.goods));
		    dynamicCommodity.setPriceType(ToolCopy.copyObject(this.priceType));
		    dynamicCommodity.setPriceVal(ToolCopy.copyObject(this.priceVal));
		    dynamicCommodity.setAddedTime(ToolCopy.copyObject(this.addedTime));
		    dynamicCommodity.setShelfTime(ToolCopy.copyObject(this.shelfTime));
		    dynamicCommodity.setCreateDate(ToolCopy.copyObject(this.createDate));
		    dynamicCommodity.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    dynamicCommodity.indexValues = ArrayUtils.clone(indexValues);
			return dynamicCommodity;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return dynamicCommodity;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.name);
        map.put(keys[2], this.storeId);
        map.put(keys[3], this.grid);
        map.put(keys[4], this.tagIcon);
        map.put(keys[5], this.openContType);
        map.put(keys[6], this.openContVal);
        map.put(keys[7], this.weight);
        map.put(keys[8], this.limitType);
        map.put(keys[9], this.limitVal);
        map.put(keys[10], this.serLimit);
        map.put(keys[11], this.sellTime);
        map.put(keys[12], this.goods);
        map.put(keys[13], this.priceType);
        map.put(keys[14], this.priceVal);
        map.put(keys[15], this.des);
        map.put(keys[16], this.addedTime);
        map.put(keys[17], this.shelfTime);
        map.put(keys[18], this.status);
        map.put(keys[19], this.createDate);
        map.put(keys[20], this.modifiedDate);
        return map;
    }
    
    protected DynamicCommodity createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.name = (String)map.get(keys[1]);
   		this.storeId = (int)map.get(keys[2]);
   		this.grid = (int[])map.get(keys[3]);
   		this.tagIcon = (String)map.get(keys[4]);
   		this.openContType = (int)map.get(keys[5]);
   		this.openContVal = (int)map.get(keys[6]);
   		this.weight = (int)map.get(keys[7]);
   		this.limitType = (int)map.get(keys[8]);
   		this.limitVal = (int)map.get(keys[9]);
   		this.serLimit = (int)map.get(keys[10]);
   		this.sellTime = (String)map.get(keys[11]);
   		this.goods = (Map)map.get(keys[12]);
   		this.priceType = (int[])map.get(keys[13]);
   		this.priceVal = (int[])map.get(keys[14]);
   		this.des = (String)map.get(keys[15]);
   		this.addedTime = (java.util.Date)map.get(keys[16]);
   		this.shelfTime = (java.util.Date)map.get(keys[17]);
   		this.status = (int)map.get(keys[18]);
   		this.createDate = (java.util.Date)map.get(keys[19]);
   		this.modifiedDate = (java.util.Date)map.get(keys[20]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.name);
        obj.put(keys[2], this.storeId);
        obj.put(keys[3], this.grid);
        obj.put(keys[4], this.tagIcon);
        obj.put(keys[5], this.openContType);
        obj.put(keys[6], this.openContVal);
        obj.put(keys[7], this.weight);
        obj.put(keys[8], this.limitType);
        obj.put(keys[9], this.limitVal);
        obj.put(keys[10], this.serLimit);
        obj.put(keys[11], this.sellTime);
        obj.put(keys[12], this.goods);
        obj.put(keys[13], this.priceType);
        obj.put(keys[14], this.priceVal);
        obj.put(keys[15], this.des);
        obj.put(keys[16], this.addedTime);
        obj.put(keys[17], this.shelfTime);
        obj.put(keys[18], this.status);
        obj.put(keys[19], this.createDate);
        obj.put(keys[20], this.modifiedDate);
        return obj;
    }
    
    protected DynamicCommodity createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.name = obj.getString(keys[1]);
	    this.storeId = obj.getIntValue(keys[2]);
		this.grid = obj.getObject(keys[3],int[].class);
	    this.tagIcon = obj.getString(keys[4]);
	    this.openContType = obj.getIntValue(keys[5]);
	    this.openContVal = obj.getIntValue(keys[6]);
	    this.weight = obj.getIntValue(keys[7]);
	    this.limitType = obj.getIntValue(keys[8]);
	    this.limitVal = obj.getIntValue(keys[9]);
	    this.serLimit = obj.getIntValue(keys[10]);
	    this.sellTime = obj.getString(keys[11]);
		this.goods = obj.getObject(keys[12],Map.class);
		this.priceType = obj.getObject(keys[13],int[].class);
		this.priceVal = obj.getObject(keys[14],int[].class);
	    this.des = obj.getString(keys[15]);
	    this.addedTime = obj.getDate(keys[16]);
	    this.shelfTime = obj.getDate(keys[17]);
	    this.status = obj.getIntValue(keys[18]);
	    this.createDate = obj.getDate(keys[19]);
	    this.modifiedDate = obj.getDate(keys[20]);
        return this;
    }
    
    
    public DynamicCommodity createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.name = rs.getString(SOURCE_COLUMN_NAMES[1]);
	    this.storeId = rs.getInt(SOURCE_COLUMN_NAMES[2]);
		this.grid = forJsonObject(rs.getString(SOURCE_COLUMN_NAMES[3]),int[].class);
	    this.tagIcon = rs.getString(SOURCE_COLUMN_NAMES[4]);
	    this.openContType = rs.getInt(SOURCE_COLUMN_NAMES[5]);
	    this.openContVal = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    this.weight = rs.getInt(SOURCE_COLUMN_NAMES[7]);
	    this.limitType = rs.getInt(SOURCE_COLUMN_NAMES[8]);
	    this.limitVal = rs.getInt(SOURCE_COLUMN_NAMES[9]);
	    this.serLimit = rs.getInt(SOURCE_COLUMN_NAMES[10]);
	    this.sellTime = rs.getString(SOURCE_COLUMN_NAMES[11]);
		this.goods = forJsonObject(rs.getString(SOURCE_COLUMN_NAMES[12]),Map.class);
		this.priceType = forJsonObject(rs.getString(SOURCE_COLUMN_NAMES[13]),int[].class);
		this.priceVal = forJsonObject(rs.getString(SOURCE_COLUMN_NAMES[14]),int[].class);
	    this.des = rs.getString(SOURCE_COLUMN_NAMES[15]);
	    this.addedTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[16]);
	    this.shelfTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[17]);
	    this.status = rs.getInt(SOURCE_COLUMN_NAMES[18]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[19]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[20]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeString(this.name);
	    byteBuf.writeInt(this.storeId);
	    byteBuf.writeObject(this.grid);
	    byteBuf.writeString(this.tagIcon);
	    byteBuf.writeInt(this.openContType);
	    byteBuf.writeInt(this.openContVal);
	    byteBuf.writeInt(this.weight);
	    byteBuf.writeInt(this.limitType);
	    byteBuf.writeInt(this.limitVal);
	    byteBuf.writeInt(this.serLimit);
	    byteBuf.writeString(this.sellTime);
	    byteBuf.writeObject(this.goods);
	    byteBuf.writeObject(this.priceType);
	    byteBuf.writeObject(this.priceVal);
	    byteBuf.writeString(this.des);
	    byteBuf.writeDate(this.addedTime);
	    byteBuf.writeDate(this.shelfTime);
	    byteBuf.writeInt(this.status);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected DynamicCommodity readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.name = byteBuf.readString(null);
	    this.storeId = byteBuf.readInt(null);
	    this.grid = byteBuf.readIntArray(null);
	    this.tagIcon = byteBuf.readString(null);
	    this.openContType = byteBuf.readInt(null);
	    this.openContVal = byteBuf.readInt(null);
	    this.weight = byteBuf.readInt(null);
	    this.limitType = byteBuf.readInt(null);
	    this.limitVal = byteBuf.readInt(null);
	    this.serLimit = byteBuf.readInt(null);
	    this.sellTime = byteBuf.readString(null);
	    this.goods = (Map)byteBuf.readObject();
	    this.priceType = byteBuf.readIntArray(null);
	    this.priceVal = byteBuf.readIntArray(null);
	    this.des = byteBuf.readString(null);
	    this.addedTime = byteBuf.readDate(null);
	    this.shelfTime = byteBuf.readDate(null);
	    this.status = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public DynamicCommodity insert(){
    	return DynamicCommodityCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public DynamicCommodity update(){
    	return DynamicCommodityCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return DynamicCommodityCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public DynamicCommodity insertAndFlush(){
    	return DynamicCommodityCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public DynamicCommodity updateAndFlush(){
    	return DynamicCommodityCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return DynamicCommodityCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public DynamicCommodity syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}